/*************************************************
Author: Aven
Date: 12/03/2013
Description:
Notes:
*************************************************/

#ifndef __CFamilyDiceMgr_h__
#define __CFamilyDiceMgr_h__

#include "commerrno.h"
#include "commmsg.h"
#include "CDiceCfg.h"
#include "MsgAct.pb.h"
#include "../item/CDropItem.h"
#include "../clan/CClanMgr.h"

enum DiceReqType
{
    CONST_DICE_GET_INFO     = 0,    //获取闯关信息
    CONST_DICE_SHAKE_COMMON   = 1,    //投骰子
    CONST_DICE_SHAKE_BUY      = 2,    //金币购买投骰子
};

class CFamilyDiceMgr
{
public:

    CFamilyDiceMgr()
    {
        m_bStatusChange = false;
    }

    virtual ~CFamilyDiceMgr()
    {
    }

    int Init()
    {
        _stFamilyDiceCfg.Init();
        return 0;
    }

    int InitClanDice (CClanEntry & stClanEntry, CClanData & stClanData);

    int DoReq(MsgReqFamilyDice &stReq, MsgAnsFamilyDice & stAns);

    //初始化闯关的最好记录
    void InitDiceBestRecord (CPlayerDetailInfo& stPlayerDetail, int iNowTime);
    void UpdateBestRecord (CPlayerDetailInfo& stPlayerDetail, int iBestWeekPos);

    //是否家族用户
    bool IsClanUser(unsigned int uiGid);

    int GetRandomRange(int iMin, int iMax);

    //免费投骰子
    int DiceShakeCommon(unsigned int uiGid, MsgAnsFamilyDice & stAns);

    //金币购买投骰子
    int DiceShakeBuy(unsigned int uiGid, MsgAnsFamilyDice & stAns);

    int GetDiceCount(CPlayerBaseInfo& stPlayerBase,
        CPlayerDetailInfo& stPlayerDetail);

    int DiceShake(CPlayerDetailInfo& stPlayerDetailInfo, MsgAnsFamilyDice & stAns);

    //触发奖励
    int TriggerAward(unsigned int uiGid, CDropItem& stDropItem, MsgAnsFamilyDice& stAns);

    int GetLevelAwardItems(unsigned int uiGid, CDiceLevelAwardConfigData& stData, CDropItem& stDropItem);

    int UpdateDiceStatus(CPlayerDetailInfo& stPlayerDetail);

    //获取物品
    int GetAwardItems(unsigned int uiGid, short shLevel, TAward& award, CDiceAwardRateData& stAwardRateData, CDropItem& stDropItem);

    //获取基本信息
    int GetFamilyDiceBaseInfo(CPlayerDetailInfo& stPlayerDetailInfo, MsgAnsFamilyDice & stAns);

    //获取家族闯关信息
    int GetFamilyDiceInfo(unsigned int uiGid, MsgAnsFamilyDice & stAns);

    int LoadConfig(const char* szCfgPath);

    //获取闯关排行榜奖励
    int GetDiceRankBonus (unsigned char ucRank, CDropItemData & stBonus);

    int GetAccountTime (int iNowTime);

private:
    bool m_bStatusChange;
    CFamilyDiceConfig _stFamilyDiceCfg;
};

#endif //__CFamilyDiceMgr_h__
